﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
using Rhomble.Data;

namespace Rhomble.Services.Projects
{
	public class ProjectModel
	{
		[ScaffoldColumn(false)]
		public Guid ID { get; set; }

		[Required]
		[StringLength(200)]
		public string Name { get; set; }

		[ScaffoldColumn(false)]
		public string Customer { get; set; }

		[ScaffoldColumn(false)]
		public Guid? CustomerFK { get; set; }

		[ScaffoldColumn(false)]
		public DateTime CreatedDate { get; set; }

		[ScaffoldColumn(false)]
		public string CreatedBy { get; set; }

		[ScaffoldColumn(false)]
		public Guid CreatedByFK { get; set; }
	}

	internal static class ProjectTransforms
	{
		internal static Expression<Func<Project, ProjectModel>> EntityToModel = p => new ProjectModel
		{
			ID = p.ProjectPK,
			Name = p.Name,
			Customer = p.Customer != null ? p.Customer.Name : String.Empty,
			CustomerFK = p.CustomerFK,
			CreatedDate = p.CreatedDate,
			CreatedBy = p.CreatedByUser.UserName,
			CreatedByFK = p.CreatedBy
		};

		internal static Func<ProjectModel, Project> ModelToEntity = p => new Project
		{
			Name = p.Name,
			CustomerFK = p.CustomerFK
		};
	}
}
